package com.cq.ssm.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.cq.ssm.mapper.JobMapper;
import com.cq.ssm.mapper.StuffdepartmentMapper;
import com.cq.ssm.po.Job;
import com.cq.ssm.po.Stuffdepartment;
import com.cq.ssm.service.StuffdepartmentService;

@Component("stuffdepartmentService")
public class StuffdepartmentServiceImpl implements StuffdepartmentService {

	@Autowired
	private StuffdepartmentMapper sdm;
	@Autowired
	private JobMapper jm;
	// 插入一条记录
	public boolean insertStuffdepartment(Stuffdepartment stuffdepartment) throws Exception {
		int i = sdm.insertSelective(stuffdepartment);
		return i==1?true:false;
	}

	// 根据id删除一条记录
	public boolean deleteById(Integer id) throws Exception {
		int i = sdm.deleteByPrimaryKey(id);
		return i==1?true:false;
	}

	// 查询所有记录
	public List<Stuffdepartment> findAll() throws Exception {
		return sdm.selectAllDepartment();
	}
	
	// 查询指定部门的所有职位
	public List<Job> findAllJobs(Integer idDepartment) throws Exception{
		String str = sdm.selectJobs(idDepartment);
		String[] s = str.split(",");
		List<Integer> ids = new ArrayList<Integer>();
		for (String string : s){
			ids.add(Integer.parseInt(string));
		}
		HashMap<String,List<Integer>> map = new HashMap<String, List<Integer>>();
		map.put("ids", ids);
		List<Job> jobs = jm.selectAllJob(map);
		return jobs;
	}
}
